from django import template
from announcements.models import Notification, Announcement

register = template.Library()


@register.simple_tag
def unread_notification_count(user):

    unread_notifications = Notification.objects.filter(user=user, read=False)
    unread_announcements = Announcement.objects.filter(id__in=unread_notifications.values('announcement_id'))

    return {'count': len(unread_announcements), 'announcements': unread_announcements}
